package com.sc.nft.config;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.sc.nft.pool.UserPool;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Component
public class MetaObjectHandlerConfig implements MetaObjectHandler {

  @Override
  public void insertFill(MetaObject metaObject) {
    DateTime now = DateTime.now();
    Long id = 0L;
    if(ObjectUtil.isNotNull(UserPool.getUser())){
     }

    setFieldValByName("createTime", now, metaObject);
    setFieldValByName("modifyTime", now, metaObject);
    setFieldValByName("isDelete", Boolean.FALSE, metaObject);
    setFieldValByName("createId", id, metaObject);
    setFieldValByName("modifyId", id, metaObject);
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    Long id = 0L;
    if(ObjectUtil.isNotNull(UserPool.getUser())){
      id = UserPool.getUser().getId();
    }

    setFieldValByName("modifyTime", DateTime.now(), metaObject);
    setFieldValByName("modifyId", id, metaObject);
  }
}
